<template>
	<view>
		<uni-card v-for="item,index in list" :title="item.content" thumbnail="" :extra="item.data" note="Tips">
			{{item.name}}
		</uni-card>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				offset:1,
				pageIndex: 0,
				pageSize: 10,
				list: [{
						"id": 1,
						"title": "学校的篮球场太棒了",
						"content": "学校的篮球场太棒了，专业级别，自由飞翔！",
						"date": "2019-07-19",
						"name": "张三"
					},
					{
						"id": 2,
						"title": "学校的二楼的罗宋汤太棒了",
						"content": "酸、甜、辣、咸，就差一样苦，四味俱全！",
						"date": "2019-07-20",
						"name": "张三"
					},
					{
							"id": 1,
							"title": "学校的篮球场太棒了",
							"content": "学校的篮球场太棒了，专业级别，自由飞翔！",
							"date": "2019-07-19",
							"name": "张三"
						},
					{
							"id": 1,
							"title": "学校的篮球场太棒了",
							"content": "学校的篮球场太棒了，专业级别，自由飞翔！",
							"date": "2019-07-19",
							"name": "张三"
						},
						{
							"id": 1,
							"title": "学校的篮球场太棒了",
							"content": "学校的篮球场太棒了，专业级别，自由飞翔！",
							"date": "2019-07-19",
							"name": "张三"
						},
						{
								"id": 1,
								"title": "学校的篮球场太棒了",
								"content": "学校的篮球场太棒了，专业级别，自由飞翔！",
								"date": "2019-07-19",
								"name": "张三"
							},
							{
									"id": 1,
									"title": "学校的篮球场太棒了",
									"content": "学校的篮球场太棒了，专业级别，自由飞翔！",
									"date": "2019-07-19",
									"name": "张三"
								},
								{
										"id": 1,
										"title": "学校的篮球场太棒了",
										"content": "学校的篮球场太棒了，专业级别，自由飞翔！",
										"date": "2019-07-19",
										"name": "张三"
									},
				]
			}
		},
		onLoad(opt) {
			this.offset = opt.offset
			console.log(this.offset);
		},
		onPullDownRefresh() {
			//重新获取第0页的数据，更新页面list变量
			this.reload()
		},
		onReachBottom() {
			//加载更多，加载当前页的下一页，并将获取的数据追加到list中，修改当前页为下一页
			uni.showLoading({
				title: '加载中',
				mask: false
			});
			uni.request({
				url: 'http://localhost:8090/freshmenapp/message/listByPage',
				method: 'POST',
				data: {
					"offset": this.offset,
					"pageIndex": this.pageIndex + 1,
					"pageSize": this.pageSize
				},
				success: res => {
					this.list = [...this.list, ...res.data.data]
					if (this.pageIndex < res.data.data.totalPages) {
						this.pageIndex = this.pageIndex + 1
					} else {

					}
					setTimeout(() => {
						uni.hideLoading()
					}, 3000)
				},
				fail: () => {},
				complete: () => {}
			});
		},
		methods: {
			reload() {
				uni.request({
					url: 'http://localhost:8090/freshmenapp/message/listByPage',
					method: 'POST',
					data: {
						"offset":this.offset,
						"pageIndex": 0,
						"pageSize": this.pageSize
					},
					success: res => {
						if (res.data.success) {
							console.log(res.data);
							this.list = res.data.data
							uni.stopPullDownRefresh();
							uni.showToast({
								title: '刷新成功'
							});
						} else {

						}
					},
					fail: () => {},
					complete: () => {}
				});
			}
		}
	}
</script>

<style>

</style>